package com.fishing.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fishing.util.personal.GameName;
import com.fishing.util.personal.Guild_SortField;

import QL.ButlerGameDifficultyItem;
import QL.ButlerGameDifficultyQueryRequest;
import QL.ButlerGameDifficultyQueryResponse;
import QL.ButlerGameDifficultySetRequest;
import QL.ButlerGameDifficultySetResponse;
import QL.ButlerGuildGetListRequest;
import QL.ButlerGuildGetListResponse;
import QL.QLClient;

/**
 * 游戏难度控制相关
 * */
@Controller
public class RoomDifficultController {

	private static QLClient client = new QLClient();
	
	//region 游戏设置难度页面
	@RequestMapping("game/Difficultset")
	public ModelAndView Difficultset( HttpServletRequest request)throws Exception{
    	ModelAndView mv = new ModelAndView("game/difficultset");
    	return mv;
	}
	//endregion
	
	//region 游戏统计难度页面
	@RequestMapping("game/DiificultStatistics")
	public ModelAndView DiificultStatistics( HttpServletRequest request)throws Exception{
    	ModelAndView mv = new ModelAndView("game/diificultStatistics");
    	return mv;
	}
    //endregion

    //region
	@ResponseBody
	@RequestMapping(value="Room/SetGameDifficult",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    public  String SetGameDifficult(HttpServletRequest request,String DifficultSelect,String DifficultSet) {
		Map<String,Object> map = new HashMap<String, Object>();
		ButlerGameDifficultySetRequest req = new ButlerGameDifficultySetRequest();
		//发送协议
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		req.GroupId = Integer.parseInt(Arrays.asList(DifficultSelect.split(",")).get(0));
		req.ServiceId = Integer.parseInt(Arrays.asList(DifficultSelect.split(",")).get(1));
		req.DifficultyLevel = Integer.parseInt(DifficultSet);
		req.Operater = (String)request.getSession().getAttribute("Admintruename");
		ButlerGameDifficultySetResponse rsp = new ButlerGameDifficultySetResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		
		//处理返回值
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) 
			return "success";
		else
			return rsp.ErrMsg;
	}
	//endregion

	//region
	@ResponseBody
	@RequestMapping(value="Room/StatisticsGameDifficult",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    public  Map<String,Object> StatisticsGameDifficult(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String, Object>();
		ButlerGameDifficultyQueryRequest req = new ButlerGameDifficultyQueryRequest();
		//发送协议
		req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
		ButlerGameDifficultyQueryResponse rsp = new ButlerGameDifficultyQueryResponse();
		if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
		
		//处理返回值
		if (rsp.ErrMsg == "" || rsp.ErrMsg == null) {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", rsp.Items.size());
			map.put("data", rsp.Items);
			return map;
		}
		else {
			map.put("status", "200");
			map.put("message", "");
			map.put("count", 0);
			map.put("data", 0);
			return map;
		}
	}
	//endregion
}
